package androidx.core.graphics.drawable;

import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Icon;
import android.os.Build.VERSION;
import android.os.Parcelable;
import android.util.Log;
import androidx.annotation.DrawableRes;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.versionedparcelable.CustomVersionedParcelable;
import com.huawei.hms.framework.network.grs.GrsBaseInfo$CountryCodeSource;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.charset.Charset;

public class IconCompat extends CustomVersionedParcelable {
    static final Mode ᐝ = Mode.SRC_IN;
    Mode ʻ = ᐝ;
    @RestrictTo({d.LIBRARY})
    public String ʼ = null;
    @RestrictTo({d.LIBRARY})
    public ColorStateList ʽ = null;
    @RestrictTo({d.LIBRARY_GROUP_PREFIX})
    public int ˊ = -1;
    @RestrictTo({d.LIBRARY})
    public Parcelable ˋ = null;
    @RestrictTo({d.LIBRARY})
    public byte[] ˎ = null;
    @RestrictTo({d.LIBRARY})
    public int ˏ = 0;
    Object ॱ;
    @RestrictTo({d.LIBRARY})
    public int ॱॱ = 0;

    @RestrictTo({d.LIBRARY})
    @Retention(RetentionPolicy.SOURCE)
    public @interface IconType {
    }

    @NonNull
    public String ॱ() {
        if (this.ˊ == -1 && VERSION.SDK_INT >= 23) {
            return ˊ((Icon) this.ॱ);
        }
        if (this.ˊ == 2) {
            return ((String) this.ॱ).split(":", -1)[0];
        }
        throw new IllegalStateException("called getResPackage() on " + this);
    }

    @IdRes
    public int ˋ() {
        if (this.ˊ == -1 && VERSION.SDK_INT >= 23) {
            return ॱ((Icon) this.ॱ);
        }
        if (this.ˊ == 2) {
            return this.ˏ;
        }
        throw new IllegalStateException("called getResId() on " + this);
    }

    public String toString() {
        if (this.ˊ == -1) {
            return String.valueOf(this.ॱ);
        }
        StringBuilder append = new StringBuilder("Icon(typ=").append(ˎ(this.ˊ));
        switch (this.ˊ) {
            case 1:
            case 5:
                append.append(" size=").append(((Bitmap) this.ॱ).getWidth()).append("x").append(((Bitmap) this.ॱ).getHeight());
                break;
            case 2:
                append.append(" pkg=").append(ॱ()).append(" id=").append(String.format("0x%08x", new Object[]{Integer.valueOf(ˋ())}));
                break;
            case 3:
                append.append(" len=").append(this.ˏ);
                if (this.ॱॱ != 0) {
                    append.append(" off=").append(this.ॱॱ);
                    break;
                }
                break;
            case 4:
                append.append(" uri=").append(this.ॱ);
                break;
        }
        if (this.ʽ != null) {
            append.append(" tint=");
            append.append(this.ʽ);
        }
        if (this.ʻ != ᐝ) {
            append.append(" mode=").append(this.ʻ);
        }
        append.append(")");
        return append.toString();
    }

    public void ˊ(boolean z) {
        this.ʼ = this.ʻ.name();
        switch (this.ˊ) {
            case -1:
                if (z) {
                    throw new IllegalArgumentException("Can't serialize Icon created with IconCompat#createFromIcon");
                }
                this.ˋ = (Parcelable) this.ॱ;
                return;
            case 1:
            case 5:
                if (z) {
                    Bitmap bitmap = (Bitmap) this.ॱ;
                    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    bitmap.compress(CompressFormat.PNG, 90, byteArrayOutputStream);
                    this.ˎ = byteArrayOutputStream.toByteArray();
                    return;
                }
                this.ˋ = (Parcelable) this.ॱ;
                return;
            case 2:
                this.ˎ = ((String) this.ॱ).getBytes(Charset.forName("UTF-16"));
                return;
            case 3:
                this.ˎ = (byte[]) this.ॱ;
                return;
            case 4:
                this.ˎ = this.ॱ.toString().getBytes(Charset.forName("UTF-16"));
                return;
            default:
                return;
        }
    }

    public void ˊ() {
        this.ʻ = Mode.valueOf(this.ʼ);
        switch (this.ˊ) {
            case -1:
                if (this.ˋ != null) {
                    this.ॱ = this.ˋ;
                    return;
                }
                throw new IllegalArgumentException("Invalid icon");
            case 1:
            case 5:
                if (this.ˋ != null) {
                    this.ॱ = this.ˋ;
                    return;
                }
                this.ॱ = this.ˎ;
                this.ˊ = 3;
                this.ˏ = 0;
                this.ॱॱ = this.ˎ.length;
                return;
            case 2:
            case 4:
                this.ॱ = new String(this.ˎ, Charset.forName("UTF-16"));
                return;
            case 3:
                this.ॱ = this.ˎ;
                return;
            default:
                return;
        }
    }

    private static String ˎ(int i) {
        switch (i) {
            case 1:
                return "BITMAP";
            case 2:
                return "RESOURCE";
            case 3:
                return "DATA";
            case 4:
                return "URI";
            case 5:
                return "BITMAP_MASKABLE";
            default:
                return GrsBaseInfo$CountryCodeSource.UNKNOWN;
        }
    }

    @RequiresApi(23)
    @Nullable
    private static String ˊ(@NonNull Icon icon) {
        if (VERSION.SDK_INT >= 28) {
            return icon.getResPackage();
        }
        try {
            return (String) icon.getClass().getMethod("getResPackage", new Class[0]).invoke(icon, new Object[0]);
        } catch (Throwable e) {
            Log.e("IconCompat", "Unable to get icon package", e);
            return null;
        } catch (Throwable e2) {
            Log.e("IconCompat", "Unable to get icon package", e2);
            return null;
        } catch (Throwable e22) {
            Log.e("IconCompat", "Unable to get icon package", e22);
            return null;
        }
    }

    @RequiresApi(23)
    @IdRes
    @DrawableRes
    private static int ॱ(@NonNull Icon icon) {
        if (VERSION.SDK_INT >= 28) {
            return icon.getResId();
        }
        try {
            return ((Integer) icon.getClass().getMethod("getResId", new Class[0]).invoke(icon, new Object[0])).intValue();
        } catch (Throwable e) {
            Log.e("IconCompat", "Unable to get icon resource", e);
            return 0;
        } catch (Throwable e2) {
            Log.e("IconCompat", "Unable to get icon resource", e2);
            return 0;
        } catch (Throwable e22) {
            Log.e("IconCompat", "Unable to get icon resource", e22);
            return 0;
        }
    }
}
